package com.whisper.application.app.web.controller.front;

import com.whisper.application.service.domain.vo.VrActVo;
import com.whisper.application.service.domain.VrAct;
import com.whisper.application.service.service.IVrActService;
import com.whisper.application.service.service.IVrArticleService;
import com.whisper.common.annotation.PageQuery;
import com.whisper.common.core.controller.BaseController;
import com.whisper.common.utils.bean.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * 志愿活动Controller
 * 
 * @author whisper
 * @date 2024-01-07
 */
@RestController
@RequestMapping("/service/actVo")
public class ActController extends BaseController
{
    @Autowired
    private IVrActService vrActService;

    @Autowired
    private IVrArticleService vrArticleService;

    /**
     * 查询志愿活动列表
     */
    @PageQuery
    @GetMapping("/list")
    public List<VrActVo> list(VrAct vrAct)
    {
        List<VrAct> vrActs = vrActService.selectVrActList(vrAct);
        vrActService.checkAndUpdateStatu(vrActs);
        List<VrActVo> vrActVos = new ArrayList<>();
        vrActs.forEach( act -> {
            VrActVo actVo = new VrActVo();
            BeanUtils.copyBeanProp(actVo, act);
            actVo.setCover((vrArticleService.selectVrArticleById(Long.parseLong(act.getContent())).getCover()));
            vrActVos.add(actVo);
        });
        // 查询更新后的数据
        return vrActVos;
    }

    /**
     * 获取志愿活动详细信息
     */
    @GetMapping(value = "/{id}")
    public VrActVo getInfo(@PathVariable("id") Long id)
    {
        VrAct vrAct = vrActService.selectVrActById(id);
        VrActVo actVo = new VrActVo();
        BeanUtils.copyBeanProp(actVo, vrAct);
        actVo.setCover((vrArticleService.selectVrArticleById(Long.parseLong(vrAct.getContent())).getCover()));
        return actVo;
    }

}